﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace FtpUpload
{
    public partial class FrmLogin : Form
    {
        public FrmLogin()
        {
            InitializeComponent();
        }

        public long m_user_id = 0;

        /// <summary>
        /// 用户登陆 -1 用户不存在 -2密码错误 -3程序异常
        /// </summary> 
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_login_Click(object sender, EventArgs e)
        {
            lbl_login_info.ForeColor = Color.Green;
            lbl_login_info.Text = "正在登陆,请稍等...";
            if (string.IsNullOrEmpty(txt_user_name.Text.Trim()))
            {
                MessageBox.Show( "请输入用户名!","提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (string.IsNullOrEmpty(txt_password.Text.Trim()))
            {
                MessageBox.Show("请输入密码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            com._114sucai.ftp.Service1 t_ftp_sevice = new FtpUpload.com._114sucai.ftp.Service1();
            string t_exception_info = "登陆出现异常!";
            try
            {
                m_user_id = t_ftp_sevice.LoginUser(txt_user_name.Text.Trim(), txt_password.Text.Trim());

               
                if (m_user_id == -1)
                {
                    t_exception_info="用户不存在";
                }
                else if (m_user_id == -2)
                {
                    t_exception_info="密码错误";
                }
                else if (m_user_id == -3)
                {
                    t_exception_info="登陆出现异常";
                }
      
                if (m_user_id > 0)
                {
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    MessageBox.Show("登陆失败，" + t_exception_info, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("登陆失败，" + t_exception_info, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        /// <summary>
        /// 退出应用程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btn_exit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
